home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINPROGS / WUNZ20SR.ZIP / SELDIR.C < prev    next >
C/C++ Source or Header  |  1993-07-12  |  4KB  |  115 lines

  1. #include <string.h>
  2. #include <io.h>
  3. #include <stdio.h>
  4. #include "wizunzip.h"
  5. #include "helpids.h"
  6. #include "seldir.h"
  7.  
  8.  
  9.  
  10. BOOL FAR PASCAL SelectDirProc(HWND hDlg, WORD wMessage, WORD wParam, LONG lParam)
  11. {
  12.     static OPENFILENAME __far *lpofn = 0;
  13.     static WORD wClose;
  14.  
  15.     switch (wMessage)
  16.     {
  17.     case WM_DESTROY:
  18.         if (lpofn && lpofn->lpstrFile && (wClose == IDOK))
  19.         {
  20.             LPSTR lpszSeparator;
  21.             DWORD dwResult;        /* result of Save As Default button query */
  22.  
  23.             /* strip off filename to make directory name    */
  24.             for (lpszSeparator = lpofn->lpstrFile+lstrlen(lpofn->lpstrFile);
  25.                 lpszSeparator > lpofn->lpstrFile;
  26.                 --lpszSeparator)
  27.             {
  28.                 /* Just backed up to root directory ?
  29.                  */
  30.                 if (lpszSeparator > (lpofn->lpstrFile+2) &&
  31.                     lpszSeparator[-1] == '\\' &&
  32.                     lpszSeparator[-2] == ':')
  33.                 {
  34.                     *lpszSeparator = '\0';    /* leave the root dir's '\\' */
  35.                     break;
  36.                 }
  37.                 if ((*lpszSeparator) == '\\')
  38.                 {
  39.                     *lpszSeparator = '\0';
  40.                     break;
  41.                 }
  42.             }
  43.             /* get state of Save As Default checkbox */
  44.             dwResult = SendDlgItemMessage(hDlg , IDM_SAVE_AS_DEFAULT, BM_GETSTATE, 0, 0);
  45.             if (dwResult & 1)    /* if checked */
  46.             {
  47.                 /* save as future default */
  48.                 WritePrivateProfileString(szAppName, szDefaultUnzipToDir, 
  49.                                 lpofn->lpstrFile, szWizUnzipIniFile);
  50.  
  51.             }
  52.         }
  53.         break;
  54.     case WM_COMMAND:
  55.         // When the user presses the OK button, stick text
  56.         // into the filename edit ctrl to fool the commdlg
  57.         // into thinking a file has been chosen.
  58.         // We're just interested in the path, so any file
  59.         // name will do - so long as it doesn't match
  60.         // a directory name, we're fine
  61.  
  62.         if (wParam == IDOK)
  63.         {
  64.             SetDlgItemText(hDlg, edt1, "johnny\376\376.\375\374\373");
  65.             wClose = wParam;
  66.         }
  67.         else if (wParam == IDCANCEL)
  68.         {
  69.             wClose = wParam;
  70.         }
  71.         break;
  72.     case WM_INITDIALOG:
  73.         {
  74.             RECT    rT1, rT2;
  75.             short   nWidth, nHeight;
  76.  
  77.             lpofn = (OPENFILENAME __far *)lParam;
  78.             CenterDialog(GetParent(hDlg), hDlg); /* center on parent */
  79.  
  80.             wClose = 0;
  81.  
  82.             // Disable the filename edit ctrl
  83.             //  and the file type label
  84.             //  and the file type combo box
  85.             EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
  86.             EnableWindow(GetDlgItem(hDlg, stc2), FALSE);
  87.             EnableWindow(GetDlgItem(hDlg, cmb1), FALSE);
  88.  
  89.             GetWindowRect(GetDlgItem(hDlg, cmb2), &rT1);
  90.  
  91.             // Hide the file type label & combo box
  92.             ShowWindow(GetDlgItem(hDlg, stc2), SW_HIDE);
  93.             ShowWindow(GetDlgItem(hDlg, cmb1), SW_HIDE);
  94.  
  95.             // Extend the rectangle of the list of files
  96.             // in the current directory so that it's flush
  97.             // with the bottom of the Drives combo box
  98.             GetWindowRect(GetDlgItem(hDlg, lst1), &rT2);
  99.             nWidth = rT2.right - rT2.left;
  100.             nHeight = rT1.bottom - rT2.top;
  101.             ScreenToClient(hDlg, (LPPOINT)&rT2);
  102.             MoveWindow(GetDlgItem(hDlg, lst1),
  103.                         rT2.left, rT2.top,
  104.                         nWidth,
  105.                         nHeight,
  106.                         TRUE);          
  107.         }
  108.     default:
  109.         break;
  110.     }
  111.  
  112.     /* message not handled */
  113.     return 0;
  114. }
  115.